package net.huashitong.scheduling.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.huashitong.scheduling.databean.ResourcesDatabean;
import net.huashitong.scheduling.entity.Resources;
import net.huashitong.scheduling.filter.ResourcesFilter;
import net.huashitong.scheduling.service.ResourcesService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
/**
 * 资源清单
 * @author lzr
 *
 */
@Controller
@RequestMapping("/app/resources")
public class ResourcesController extends JsonBaseController {

	@Autowired
	private ResourcesService resourcesService;
 	
	@Override
	protected String getView(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 根据type查询
	 * @param filter
	 * @return
	 */
	@RequestMapping("/queryTypeValue")
	@ResponseBody
	public Message queryTypeValue(@RequestBody ResourcesFilter filter){
		List<Resources> lists = resourcesService.queryByType(filter);
		List<ResourcesDatabean> databeans = new ArrayList<ResourcesDatabean>();
		List<ResourcesDatabean> databeans2 = new ArrayList<ResourcesDatabean>();
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		if("2".equals(filter.getType())){
			for (Resources resources : lists) {
				if("基础设施".equals(resources.getSecType())){
					ResourcesDatabean databean = new ResourcesDatabean();
					databean.setSysId(resources.getSysId());
					databean.setTitle(resources.getTitle());
					databeans.add(databean);
				}else if("科教文卫".equals(resources.getSecType())){
					ResourcesDatabean databean = new ResourcesDatabean();
					databean.setSysId(resources.getSysId());
					databean.setTitle(resources.getTitle());
					databeans2.add(databean);
				}
			}
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("innerData", databeans);
			map.put("title", "基础设施");
			list.add(map);
			map = new HashMap<String, Object>();
			map.put("innerData", databeans2);
			map.put("title", "科教文卫");
			list.add(map);
			return coverMessage("200","数据获取成功",list);
		}else {
			for (Resources resources : lists) {
				ResourcesDatabean databean = new ResourcesDatabean();
				databean.setSysId(resources.getSysId());
				databean.setTitle(resources.getTitle());
				databeans.add(databean);
			}
			return coverMessage("200","数据获取成功",databeans);
		}
	}
	@ResponseBody
	@RequestMapping("/queryDetailValue")
	public Message queryDetailValue(@RequestBody ResourcesFilter filter){
		Resources resources = resourcesService.queryDetailValue(filter);
		ResourcesDatabean databean = new ResourcesDatabean();
		databean.setText(resources.getText());
		return coverMessage("200", "数据获取成功", databean);
		
	}
}
